﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Runtime.CompilerServices;
using Kaleido.Util.Lang;
using System.Web;
using Kaleido.Util.Mvc.Internal;

namespace Kaleido.Util.Mvc
{
    public abstract class StaticViewPage : WebViewPage<KeyArray>
    {
        public KeyArray @var
        {
            get
            {
                if (Model == null)
                    this.ViewData.Model = new KeyArray();
                return Model;
            }
        }

        protected LangHelper _ = LangHelper.Lang;

        internal IList<string> IncludedViewList
        {
            get
            {
                if (Model["##IncludedViewList##"] == null)
                {
                    var result = new List<string>();
                    var["##IncludedViewList##"] = result;
                }
                return (IList<string>)var["##IncludedViewList##"];
            }
        }

        public IHtmlString Include(string targetView)
        {
            if (!IncludedViewList.Contains(targetView))
                IncludedViewList.Add(targetView);
            Html.RenderPartial(targetView);
            return EmptyHtmlString.Instance;
        }

        public IHtmlString IncludeOnce(string targetView)
        {
            if (!IncludedViewList.Contains(targetView))
            {
                IncludedViewList.Add(targetView);
                Html.RenderPartial(targetView);
            }
            return EmptyHtmlString.Instance;
        }
        public IndexArray @array(params dynamic[] initValues)
        {
            return _.Array(initValues);
        }
        public KeyArray @array(params KeyValuePair<string, dynamic>[] initValues)
        {
            return _.Array(initValues);
        }

        public IndexArray @merge(IndexArray a1, IndexArray a2)
        {
            return _.Merge(a1, a2);
        }

        public KeyArray @merge(KeyArray a1, KeyArray a2)
        {
            return _.Merge(a1, a2);
        }
    }
}